package com.example.xlmkotlinwanandroid.ui.activity

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.widget.Toolbar
import com.example.xlmkotlinwanandroid.R

class WebActivity : AppCompatActivity() {
    private lateinit var url: String
    private lateinit var title: String
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_web)
        fetchIntent()
        initWebView()

    }

    //获取intent信息
    private fun fetchIntent() {
        url = intent.getStringExtra("url").toString()
        title = intent.getStringExtra("title").toString()
    }

    @SuppressLint("SetJavaScriptEnabled")
    private fun initWebView() {
        val webView = findViewById<WebView>(R.id.webView)
        val toolbar = findViewById<Toolbar>(R.id.toolbarTitle)
        webView.settings.javaScriptEnabled = true
        webView.loadUrl(url)
        toolbar.title = title
        //设置防止跳出APP，打开系统浏览器页面
        webView.webViewClient=WebViewClient()

    }

}